package com.ys.everydaynews.ui.main.activityy

import android.util.Log
import androidx.fragment.app.Fragment
import com.flyco.tablayout.listener.CustomTabEntity
import com.flyco.tablayout.listener.OnTabSelectListener
import com.ys.everydaynews.R
import com.ys.everydaynews.base.BaseActivity
import com.ys.everydaynews.base.Constants.HOME_BAR
import com.ys.everydaynews.databinding.ActivityMainBinding
import com.ys.everydaynews.ui.main.adapter.HomePageAdapter
import com.ys.everydaynews.ui.main.fragment.ChatFragment
import com.ys.everydaynews.ui.main.fragment.HomeFragment
import com.ys.everydaynews.ui.main.fragment.ListFragment
import com.ys.everydaynews.ui.main.fragment.MineFrament
import com.ys.everydaynews.ui.main.model.TitleModel
import com.ys.everydaynews.ui.main.presenter.MainPresenter
import com.ys.everydaynews.ui.main.view.MainView
import com.ys.everydaynews.utils.StatusBarUtils

class MainActivity : BaseActivity<MainView, MainPresenter, ActivityMainBinding>(), MainView {

    private val titleTabs = ArrayList<CustomTabEntity>()
    private val fragmentList = ArrayList<Fragment>()

    override fun getLayoutId(): Int = R.layout.activity_main
    override fun isRegister(): Boolean = false
    override fun initView() {
        //状态栏颜色
        setLight_Red_Bar()
        val titles = resources.getStringArray(R.array.title)
        val selectIds = resources.obtainTypedArray(R.array.select)
        val unSelectIds = resources.obtainTypedArray(R.array.unselect)
        for (i: Int in titles.indices) {
            titleTabs.add(
                TitleModel(
                    titles[i],
                    selectIds.getResourceId(i, 0),
                    unSelectIds.getResourceId(i, 0),
                )
            )
        }
        fragmentList.add(HomeFragment())
        fragmentList.add(ListFragment())
        fragmentList.add(ChatFragment())
        fragmentList.add(MineFrament())
        binding.vpHome.adapter = HomePageAdapter(supportFragmentManager, fragmentList)
        binding.vpHome.offscreenPageLimit = fragmentList.size
        binding.ctlHome.setTabData(titleTabs)
        binding.ctlHome.setOnTabSelectListener(object : OnTabSelectListener {
            override fun onTabSelect(position: Int) {
                binding.vpHome.setCurrentItem(position, false)
                when (position) {
                    0, 1, 2 -> setLight_Red_Bar()
                    3 -> setLight_White_Bar()
                }
            }

            override fun onTabReselect(position: Int) {

            }

        })
    }

    override fun initData() {
    }

    override fun createPersenter() = MainPresenter()

    override fun <T> setData(data: T) {
        Log.e("test", "==> $data")
    }

    override fun setError(err: String) {
    }
}